﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace UsingSqlCommandBuilder
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string constr = "Data Source=.;Initial Catalog=Northwind;Integrated Security=true;";
            SqlConnection conn = new SqlConnection(constr);
            SqlDataAdapter sda = new SqlDataAdapter("Select * From Employees;", conn);
            SqlCommandBuilder scb = new SqlCommandBuilder(sda);
            SqlCommand cmd = new SqlCommand();
            DataSet ds = new DataSet();
            sda.Fill(ds, "Employees");
            #region output the data
            if (ds.Tables["Employees"].Rows.Count == 0)
            {
                Response.Write("没有数据");
            }
            else
            {
                for (int i = 0; i <ds.Tables["Employees"].Rows.Count; i++)
                {
                    Response.Write(ds.Tables["Employees"].Rows[i][0]);
                    Response.Write(ds.Tables["Employees"].Rows[i][1]);
                    Response.Write("<br>");
                }
            }
           #endregion 
            DataRow dr = ds.Tables["Employees"].NewRow();
            dr[0] = 10;
            dr[1] = "hua";
            dr[2] = "jianhua";
            ds.Tables["Employees"].Rows.Add(dr);
            sda.Update(ds, "Employees");
        }
    }
}
